import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";

//--------------------------------房间类型-------------------------------

export type RoomType = {
  typeId: number;
  typeName: string;
  bedType: string;
  area: number;
  facilities: string | null;
  basePrice: number;
};

/** 获取房间类型列表 */
export const getRoomTypeList = () => {
  return http.request<any>("get", baseUrlApi("room-type/list"));
};

/** 更新房间类型 */
export const updateRoomType = (data: RoomType) => {
  return http.request<any>("put", baseUrlApi("room-type/update"), { data });
};

/** 创建房间类型 */
export const createRoomType = (data: RoomType) => {
  return http.request<any>("post", baseUrlApi("room-type/create"), { data });
};

/** 删除房间类型 */
export const deleteRoomType = (typeId: number) => {
  return http.request<any>("delete", baseUrlApi(`room-type/delete/${typeId}`));
};

//--------------------------------房间详情-----------------------------

export enum RoomStatus {
  AVALIABLE = "AVALIABLE",
  BOOKED = "BOOKED",
  CHECKED_IN = "CHECKED_IN",
  CHECKED_OUT = "CHECKED_OUT",
  CLEANING = "CLEANING",
  MAINTENANCE = "MAINTENANCE",
  VACANT = "VACANT"
}

export type Room = {
  roomId: number;
  roomTypeId: number;
  roomNumber: string;
  status: RoomStatus;
  isDeleted: boolean;
};

/** 获取房间列表 */
export const getRoomList = () => {
  return http.request<any>("get", baseUrlApi("room/list"));
};

/** 更新单个房间 */
export const updateRoom = (rooms: Room) => {
  return http.request<any>("put", baseUrlApi("room/update"), {
    data: rooms
  });
};

/** 批量更新房间 */
export const batchUpdateRoom = (rooms: Room[]) => {
  return http.request<any>("put", baseUrlApi("room/update/batch"), {
    data: rooms
  });
};

/** 创建房间 */
export const createRoom = (roomNumbers: number[]) => {
  return http.request<any>("post", baseUrlApi("room/create/batch"), {
    data: roomNumbers
  });
};

/** 按房间号删除房间 */
export const deleteRoom = (roomNumbers: string[]) => {
  return http.request<any>("delete", baseUrlApi(`room/delete/batch`), {
    data: roomNumbers
  });
};

/** 按房间类型删除房间 */
export const deleteRoomByType = (typeId: number) => {
  return http.request<any>("delete", baseUrlApi(`room/delete/type/${typeId}`));
};

//--------------------------------房间价格-----------------------------
export type RoomPrice = {
  roomTypeId: number;
  price: number;
  date: string;
};

export type DailyRoomPrice = {
  date: string;
  roomPrices: RoomPrice[];
};

/** 按时间范围获取房间价格 */
export const getRoomPriceByTime = (startTime: string, endTime: string) => {
  return http.request<{
    code: number;
    msg: string;
    data: DailyRoomPrice[];
  }>(
    "get",
    baseUrlApi(
      `/room-price/list/range?startTime=${startTime}&endTime=${endTime}`
    )
  );
};

/** 更新单日房间价格 */
export const updateRoomPrice = (data: RoomPrice) => {
  return http.request<any>("put", baseUrlApi("room-price/update"), { data });
};

/** 更新日期范围内的房间价格 */
export const updateRoomPriceByDateRange = (
  startTime: string,
  endTime: string,
  data: RoomPrice
) => {
  return http.request<any>(
    "put",
    baseUrlApi(
      `room-price/update/range?startTime=${startTime}&endTime=${endTime}`
    ),
    {
      data
    }
  );
};
